#include "mesh.h"



//-------------------------------------------------------------------------
void 
Mesh::setNode( int _id,double _cX, double _cY, double _cZ )
{
  // seria interessante verificar:
  // -> se id e positiva
  // -> se ja nao existe algum outro no com o mesmo id
  m_nodes[_id].push_back( _cX );
  m_nodes[_id].push_back( _cY );
  m_nodes[_id].push_back( _cZ );
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
void 
Mesh::setElem( int _id, int _nN, int* _pNodes )
{
  // seria interessante verificar:
  // -> se id e positiva
  // -> se ja nao existe algum outro elemento com o mesmo id
  for(int i=0; i<_nN; i++)
    m_elems[_id].push_back( _pNodes[i] );
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
void 
Mesh::getBoundingBox( double& _minX, double& _maxX,
                      double& _minY, double& _maxY,
                      double& _minZ, double& _maxZ )
{
  // determina a bounding box do modelo (xmin,ymin,xmax,ymax)
  int numNodes = m_nodes.size();
  if(numNodes!=0)
  {
    _minX = m_nodes[1][0];
    _maxX = m_nodes[1][0];
    _minY = m_nodes[1][1];
    _maxY = m_nodes[1][1];
    _minZ = m_nodes[1][2];
    _maxZ = m_nodes[1][2];
    for(int i=2;i<=numNodes;i++)
    {
      if( m_nodes[i][0] < _minX )
        _minX = m_nodes[i][0];
      else if( m_nodes[i][0] > _maxX )
        _maxX = m_nodes[i][0];
      if( m_nodes[i][1] < _minY )
        _minY = m_nodes[i][1];
      else if( m_nodes[i][1] > _maxY )
        _maxY = m_nodes[i][1];
      if( m_nodes[i][2] < _minZ )
        _minZ = m_nodes[i][2];
      else if( m_nodes[i][2] > _maxZ )
        _maxZ = m_nodes[i][2];
    }
  }
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
std::map< int, std::vector<double> >
Mesh::getNodes()
{
  return m_nodes;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
std::map< int, std::vector<int> >    
Mesh::getElems()
{
  return m_elems;
}
//-------------------------------------------------------------------------

